const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('medicine_lib', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true
    },
    medicine_name: {
      type: DataTypes.CHAR(100),
      allowNull: false
    },
    storage_time: {
      type: DataTypes.DATE,
      allowNull: false
    },
    lot_identification_mark: {
      type: DataTypes.CHAR(100),
      allowNull: true
    },
    specification: {
      type: DataTypes.CHAR(100),
      allowNull: true
    },
    sort_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'drug_sort',
        key: 'id'
      }
    },
    dose: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'dose',
        key: 'id'
      }
    },
    amount: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    out_amount: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    unit_price: {
      type: DataTypes.DOUBLE,
      allowNull: false
    },
    sell_price: {
      type: DataTypes.DOUBLE,
      allowNull: false
    },
    manufacture_date: {
      type: DataTypes.DATE,
      allowNull: false
    },
    expiration_date: {
      type: DataTypes.DATE,
      allowNull: false
    },
    expiration_flag: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    manufacturer: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'medicine_enterprise',
        key: 'id'
      }
    },
    provider: {
      type: DataTypes.CHAR(200),
      allowNull: true
    },
    conservator: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      references: {
        model: 'user',
        key: 'id'
      }
    },
    memo: {
      type: DataTypes.TEXT,
      allowNull: true
    }
  }, {
    sequelize,
    tableName: 'medicine_lib',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "FK_medicine_lib_drug_sort",
        using: "BTREE",
        fields: [
          { name: "sort_id" },
        ]
      },
      {
        name: "FK_medicine_lib_manufacturer",
        using: "BTREE",
        fields: [
          { name: "manufacturer" },
        ]
      },
      {
        name: "FK_medicine_lib_conservator",
        using: "BTREE",
        fields: [
          { name: "conservator" },
        ]
      },
      {
        name: "FK_medicine_lib_dose",
        using: "BTREE",
        fields: [
          { name: "dose" },
        ]
      },
    ]
  });
};
